//
//  WYHeroAlertController.m
//  Boss
//
//  Created by admin on 2018/8/24.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "WYHeroAlertController.h"
#import "UIButton+WYColor.h"
#import "WXApi.h"
@interface WYHeroAlertController ()
@property (strong, nonatomic) IBOutlet UIView *backgroundView;
@property (strong, nonatomic) IBOutlet UIImageView *userImageView;

@property (strong, nonatomic) IBOutlet UIButton *showOff;

@property (strong, nonatomic) IBOutlet UILabel *userName;

@property (strong, nonatomic) IBOutlet UIView *centerView;


@property (strong, nonatomic) IBOutlet UIImageView *profitImageView;
@property (strong, nonatomic) IBOutlet UILabel *profitUserName;


@property (strong, nonatomic) IBOutlet UIButton *showOffBtn;


@property (strong, nonatomic) IBOutlet UIImageView *redPacketImageView;
@property (strong, nonatomic) IBOutlet UILabel *redPacketName;

@property (strong, nonatomic) IBOutlet UIImageView *inviationImageView;
@property (strong, nonatomic) IBOutlet UILabel *inviationName;
@property (strong, nonatomic) IBOutlet UIImageView *normalUserImageView;
@property (strong, nonatomic) IBOutlet UILabel *normalUserName;

@property (strong, nonatomic) IBOutlet UIImageView *normalQRCode;

@property (strong, nonatomic) IBOutlet UIImageView *qrCode;

@property (strong, nonatomic) IBOutlet UIView *backGroundView1;

@property (strong, nonatomic) IBOutlet UIView *backGroundView2;

@property (strong, nonatomic) IBOutlet UILabel *dateLabel;

@property (strong, nonatomic) IBOutlet UILabel *countLabel;


@property (strong, nonatomic) IBOutlet UILabel *qrLabel;

@property (strong, nonatomic) IBOutlet UILabel *nameLabel;
@property (strong, nonatomic) IBOutlet UIImageView *iconHeroImageView;

@property (strong, nonatomic) IBOutlet UIImageView *icon_hero_crown;
@property (strong, nonatomic) IBOutlet UIImageView *invitaionImageView;
@property (strong, nonatomic) IBOutlet UILabel *proLabel;
@property (strong, nonatomic) IBOutlet UILabel *redpacketLabel;

@property (strong, nonatomic) IBOutlet UILabel *inviationLabel;
@property (strong, nonatomic) IBOutlet UIView *shareNormalView;
@property (strong, nonatomic) IBOutlet UILabel *normalTapLabel;

@property (strong, nonatomic) IBOutlet UIImageView *GradientBackgroundColor;


@property (strong, nonatomic) IBOutlet UIImageView *GradientBackgroundColorNormal;

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *cownHeight;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *cownWidth;

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *qrHeight;

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *qrWidth;

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *normalTopHeight;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *normalTopheight1;


@property (strong, nonatomic) IBOutlet NSLayoutConstraint *normalUserImageViewWidth;

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *normalUserImageViewHeight;

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *normalQrCodeWitdh;

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *normalQrHeight;



@end

@implementation WYHeroAlertController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
    self.view.backgroundColor = [UIColor clearColor];
}
-(void)setupUI
{
    self.cownWidth.constant = 140*DUP;
    self.cownHeight.constant = 125*DUP;
    
    self.qrWidth.constant = 88 *DUP;
    self.qrHeight.constant = 88 *DUP;
    
   
    
    //[self.backgroundView.layer addSublayer:[self setGradualChangingColor:self.backgroundView fromColor:@"#002a89" toColor:@"#58139f"]];
    self.inviationName.font = kFontSystemBIgger2(11);
    self.redPacketName.font = kFontSystemBIgger2(11);
    self.profitUserName.font = kFontSystemBIgger2(11);
    
    self.redpacketLabel.font = kFontSystemBIgger2(12);
    
    self.inviationLabel.font = kFontSystemBIgger2(12);
    self.proLabel.font = kFontSystemBIgger2(12);
    if (kScreenWidth==320) {
        self.normalUserImageViewWidth.constant = 40;
        self.normalUserImageViewHeight.constant =40;
        self.normalTopHeight.constant = 15;
        self.normalTopheight1.constant = 15;
        self.normalQrCodeWitdh.constant = 66;
        self.normalQrHeight.constant = 66;
    }
    
    
//    if (<#condition#>) {
//        <#statements#>
//    }
    
    
    
    
}

-(void)setHeroRank:(WYHeroRank *)heroRank
{
    _heroRank = heroRank;
    
    self.GradientBackgroundColorNormal.image = [UIImage imageNamed:@"icon_background_orange"];
    
    
    [self.profitImageView sd_setImageWithURL:[NSURL URLWithString:heroRank.HeroList.money.userHeadUrl] placeholderImage:nil];
    self.profitUserName.text = heroRank.HeroList.money.userName;
    [self.profitImageView setCornerRadius:self.profitImageView.width/2.f];
    
    
    
    [self.redPacketImageView sd_setImageWithURL:[NSURL URLWithString:heroRank.HeroList.packet.userHeadUrl] placeholderImage:nil];
    self.redPacketName.text = heroRank.HeroList.packet.userName;
     [self.redPacketImageView setCornerRadius:self.redPacketImageView.width/2.f];
    
    
    
    
    [self.invitaionImageView sd_setImageWithURL:[NSURL URLWithString:heroRank.HeroList.people.userHeadUrl] placeholderImage:nil];
    
    [self.invitaionImageView setCornerRadius:self.invitaionImageView.width/2.f];
    
    self.inviationName.text = heroRank.HeroList.people.userName;
    self.redPacketName.text = [NSString stringWithFormat:@"%@",heroRank.HeroList.packet.userName];
    self.inviationName.text = heroRank.HeroList.people.userName;
  
    self.redpacketLabel.text = [NSString stringWithFormat:@"%@个",heroRank.HeroList.packet.packet];
    
    self.inviationLabel.text = [NSString stringWithFormat:@"%@人",heroRank.HeroList.people.people];
    self.proLabel.text = [NSString stringWithFormat:@"%.2f元",heroRank.HeroList.money.money.floatValue/1000.f];
    
    
    [self.normalQRCode sd_setImageWithURL:[NSURL URLWithString:heroRank.qrCdoe] placeholderImage:nil];
    
    
    WYUserMessage *userMessage = [WYStoreModule currentUserMessage];
    [self.normalUserImageView sd_setImageWithURL:[NSURL URLWithString:userMessage.url] placeholderImage:nil];
     [self.normalUserImageView setCornerRadius:30];
    if (kScreenWidth==320) {
         [self.normalUserImageView setCornerRadius:20];
    }
    
   
    [self.normalUserImageView setBorderWithWidth:2.f andColor:[UIColor hexStringToColor:@"#ffffff" alpha:0.8]];
    self.normalUserName.text = userMessage.userName;
    
    [self.centerView addSubview:self.backGroundView2];
    self.backGroundView2.frame = self.centerView.bounds;
    self.centerView.backgroundColor = [UIColor clearColor];
    self.backGroundView2.backgroundColor = [UIColor clearColor];
    
    
    
}






-(void)setMoenyRank:(WYHeroRank *)moenyRank
{
    _moenyRank = moenyRank;
    self.GradientBackgroundColor.image = [UIImage imageNamed:@"GradualChange"];
    self.showOffBtn.userInteractionEnabled = YES;
    WYUserMessage *userMessage = [WYStoreModule currentUserMessage];
    [self.userImageView sd_setImageWithURL:[NSURL URLWithString:userMessage.url] placeholderImage:nil];
    [self.userImageView setCornerRadius:self.userImageView.width/2.f];
    [self.userImageView setBorderWithWidth:2.f andColor:[UIColor hexStringToColor:@"#ffffff" alpha:0.8]];
    self.userName.text = userMessage.userName;
    
    [self.centerView addSubview:self.backGroundView1];
    self.backGroundView1.frame = self.centerView.bounds;
    self.centerView.backgroundColor = [UIColor clearColor];
    self.backGroundView1.backgroundColor = [UIColor clearColor];
    
    self.dateLabel.text  = [NSString stringWithFormat:@"%@-%@",moenyRank.HeroList.money.startTime,moenyRank.HeroList.money.endTime];
    self.nameLabel.text = @"累计收益";
    self.countLabel.text = [NSString stringWithFormat:@"%.2f元",moenyRank.HeroList.money.money.floatValue/1000.0];
    [self.qrCode sd_setImageWithURL:[NSURL URLWithString:moenyRank.qrCdoe] placeholderImage:nil];
    if (moenyRank.HeroList.money.moneyRanking.integerValue==1) {
        self.iconHeroImageView.image = [UIImage imageNamed:@"icon_hero_moeny_guanjun"];
        self.icon_hero_crown.image = [UIImage imageNamed:@"icon_hero_crown"];
        
        
        
    }
    if (moenyRank.HeroList.money.moneyRanking.integerValue==2) {
        self.iconHeroImageView.image = [UIImage imageNamed:@"icon_hero_moeny_yajun"];
        self.icon_hero_crown.image = [UIImage imageNamed:@"icon_hero_yinguan"];
    }
    if (moenyRank.HeroList.money.moneyRanking.integerValue==3) {
        self.iconHeroImageView.image = [UIImage imageNamed:@"icon_hero_moeny_jijun"];
        self.icon_hero_crown.image = [UIImage imageNamed:@"icon_hero_tongguan"];
    }
}

-(void)setRedpacktRank:(WYHeroRank *)redpacktRank
{
    _redpacktRank = redpacktRank;
    self.GradientBackgroundColor.image = [UIImage imageNamed:@"icon_background_green"];
    self.showOffBtn.userInteractionEnabled = YES;
    WYUserMessage *userMessage = [WYStoreModule currentUserMessage];
    [self.userImageView sd_setImageWithURL:[NSURL URLWithString:userMessage.url] placeholderImage:nil];
    [self.userImageView setCornerRadius:self.userImageView.width/2.f];
    [self.userImageView setBorderWithWidth:2.f andColor:[UIColor hexStringToColor:@"#ffffff" alpha:0.8]];
    self.userName.text = userMessage.userName;
    
    [self.centerView addSubview:self.backGroundView1];
    self.backGroundView1.frame = self.centerView.bounds;
    self.centerView.backgroundColor = [UIColor clearColor];
    self.backGroundView1.backgroundColor = [UIColor clearColor];
    
    self.dateLabel.text  = [NSString stringWithFormat:@"%@-%@",redpacktRank.HeroList.packet.startTime,redpacktRank.HeroList.packet.endTime];
    self.nameLabel.text = @"累计个数";
    self.countLabel.text = [NSString stringWithFormat:@"%@个",redpacktRank.HeroList.packet.packet];
    [self.qrCode sd_setImageWithURL:[NSURL URLWithString:redpacktRank.qrCdoe] placeholderImage:nil];
    if (redpacktRank.HeroList.packet.packetRanking.integerValue==1) {
        self.iconHeroImageView.image = [UIImage imageNamed:@"icon_hero_redPacket_Champion"];
        self.icon_hero_crown.image = [UIImage imageNamed:@"icon_hero_crown"];
    }
    if (redpacktRank.HeroList.packet.packetRanking.integerValue==2) {
        self.iconHeroImageView.image = [UIImage imageNamed:@"icon_hero_redpacket_yajun"];
        self.icon_hero_crown.image = [UIImage imageNamed:@"icon_hero_yinguan"];
    }
    if (redpacktRank.HeroList.packet.packetRanking.integerValue==3) {
        self.iconHeroImageView.image = [UIImage imageNamed:@"icon_hero_redpacket_jijun"];
        self.icon_hero_crown.image = [UIImage imageNamed:@"icon_hero_tongguan"];
    }
}
-(void)setPeopleRank:(WYHeroRank *)peopleRank
{
    _peopleRank = peopleRank;
    self.GradientBackgroundColor.image = [UIImage imageNamed:@"icon_background_purple"];
    self.showOffBtn.userInteractionEnabled = YES;
    WYUserMessage *userMessage = [WYStoreModule currentUserMessage];
    [self.userImageView sd_setImageWithURL:[NSURL URLWithString:userMessage.url] placeholderImage:nil];
    [self.userImageView setCornerRadius:self.userImageView.width/2.f];
    [self.userImageView setBorderWithWidth:2.f andColor:[UIColor hexStringToColor:@"#ffffff" alpha:0.8]];
    self.userName.text = userMessage.userName;
    
    [self.centerView addSubview:self.backGroundView1];
    self.backGroundView1.frame = self.centerView.bounds;
    self.centerView.backgroundColor = [UIColor clearColor];
    self.backGroundView1.backgroundColor = [UIColor clearColor];
    [self.backGroundView1 setCornerRadius:15.f];
    
    
    self.dateLabel.text  = [NSString stringWithFormat:@"%@-%@",peopleRank.HeroList.people.startTime,peopleRank.HeroList.people.endTime];
    self.nameLabel.text = @"累计邀请";
    self.countLabel.text = [NSString stringWithFormat:@"%@人 ",peopleRank.HeroList.people.people];
    [self.qrCode sd_setImageWithURL:[NSURL URLWithString:peopleRank.qrCdoe] placeholderImage:nil];
    if (peopleRank.HeroList.people.people.integerValue==1) {
        self.iconHeroImageView.image = [UIImage imageNamed:@"icon_hero_people_guanjun"];
        self.icon_hero_crown.image = [UIImage imageNamed:@"icon_hero_crown"];
    }
    if (peopleRank.HeroList.people.people.integerValue==2) {
        self.iconHeroImageView.image = [UIImage imageNamed:@"icon_hero_people_yajun"];
        self.icon_hero_crown.image = [UIImage imageNamed:@"icon_hero_yinguan"];
    }
    if (peopleRank.HeroList.people.people.integerValue==3) {
        self.iconHeroImageView.image = [UIImage imageNamed:@"icon_hero_people_jijun"];
        self.icon_hero_crown.image = [UIImage imageNamed:@"icon_hero_tongguan"];
    }
    
    
    
    
    
    
    
    
    
}
















- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)colseAction:(id)sender {
    [self.view removeFromSuperview];
    
    
    
}

-(void)dealloc
{
    NSLog(@"这个界面被销毁了");
    
}

- (IBAction)normalShowoffAction:(id)sender {
    
    WXMediaMessage *message = [WXMediaMessage message];
    //[message setThumbImage:[UIImage imageNamed:@"example"]];
    WXImageObject *imageObject = [WXImageObject object];
    
    self.normalQRCode.hidden = NO;
    self.normalTapLabel.hidden = NO;
    
    
    UIImage *image = [self convertViewToImage:self.shareNormalView];
    
    
//        UIImageView *imageView =[[UIImageView alloc]init];
//        imageView.frame = self.view.bounds;
//        [self.view addSubview:imageView];
//
//        imageView.image = image;
    self.normalQRCode.hidden = YES;
    self.normalTapLabel.hidden = YES;
    
    NSData *data = UIImagePNGRepresentation(image);
    imageObject.imageData = data;
    // 多媒体数据对象，可以为WXImageObject，WXMusicObject，WXVideoObject，WXWebpageObject等。
    message.mediaObject = imageObject;
    
    SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init];
    req.bText = NO;
    req.message = message;
    req.scene = WXSceneTimeline;// 分享到朋友圈
    [WXApi sendReq:req];
    
}
- (IBAction)showOFf:(id)sender {
    
    WXMediaMessage *message = [WXMediaMessage message];
    //[message setThumbImage:[UIImage imageNamed:@"example"]];
    WXImageObject *imageObject = [WXImageObject object];
    self.qrCode.hidden = NO;
    self.qrLabel.hidden = NO;
    self.backgroundView.backgroundColor = [UIColor clearColor];
    UIImage *image = [self convertViewToImage:self.backgroundView];
    
//    UIImageView *imageView =[[UIImageView alloc]init];
//    imageView.frame = self.view.bounds;
//    [self.view addSubview:imageView];
//    
//    imageView.image = image;
//    
    self.qrCode.hidden = YES;
    self.qrLabel.hidden = YES;
    NSData *data = UIImagePNGRepresentation(image);
    imageObject.imageData = data;
    // 多媒体数据对象，可以为WXImageObject，WXMusicObject，WXVideoObject，WXWebpageObject等。
    message.mediaObject = imageObject;
    
    SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init];
    req.bText = NO;
    req.message = message;
    req.scene = WXSceneTimeline;// 分享到朋友圈
    [WXApi sendReq:req];
    
    
    
    
}









-(UIImage*)convertViewToImage:(UIView*)v{
    CGSize s = v.bounds.size;
    
    
    // 下面方法，第一个参数表示区域大小。第二个参数表示是否是非透明的。如果需要显示半透明效果，需要传NO，否则传YES。第三个参数就是屏幕密度了
//    if (kScreenWidth==320) {
//        UIGraphicsBeginImageContextWithOptions(CGSizeMake(s.width, s.height+50), YES, [UIScreen mainScreen].scale);
//    }else{
        UIGraphicsBeginImageContextWithOptions(CGSizeMake(s.width, s.height), YES, [UIScreen mainScreen].scale);
//    }
    
    
    
    [v.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage*image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}

@end
